<!DOCTYPE html>
<html>
	<head>
		<style>
			html,body{
				margin: 0;
				padding: 0;
				background:#222;
				overflow: hidden;
			}
			#canvas{
			}
		</style>
		<script type="text/javascript">
		
			var x=250;
			var x1=20;
			var y=40;
			var y1=4;
			var radius=20;
			var width;
			var height;
			var dirX=1;
			var dirX1=1;
			var dirY=1;
			var dirY1=1;
			var clrWidth=500;
			var clrHeight=500;
			var cancxt;
			var animateBall;
			var animateBall1;
			window.onload=function(){
				var canvas1 = document.getElementById("canvas");
				document.addEventListener("dbclick",clrInterval,false);
				width = window.innerWidth;
				height = window.innerHeight;
				canvas1.width = width;
				canvas1.height = height;
				if(canvas1.getContext("2d"))
				{
					cancxt = canvas1.getContext("2d");
 				}else{
					alert("Your browser does not support canvas");
				}
				
				animateBall = setInterval(ball,1);
				setInterval(ball2,1);
				
			}
			
			function clrInterval(){
				//clearInterval(animateBall);
			}
			
			function ball(){
				//cancxt.clearRect(0,0,width,height);
			    var r4 = parseInt(Math.random()*255);
				var g4 = parseInt(Math.random()*255);
				var b4 = parseInt(Math.random()*255);
				var clr4 = "rgb("+r4+","+g4+","+b4+")";
				cancxt.fillStyle=clr4;
				cancxt.beginPath();
				cancxt.arc(x,y,radius,0,Math.PI*2,true);
				cancxt.closePath();
				cancxt.fill();
				
				if(x == width||x == 0){
					dirX = dirX*-1;
					}
				x=x+dirX;
				if(y == height||y == 0){
					dirY = dirY*-1;
					}
					
				radius = Math.random()*30;
				y=y+dirY;
			}

			function ball2(){
				//cancxt.clearRect(0,0,width,height);
			    var r4 = parseInt(Math.random()*255);
				var g4 = parseInt(Math.random()*255);
				var b4 = parseInt(Math.random()*255);
				var clr4 = "rgb("+r4+","+g4+","+b4+")";
				cancxt.fillStyle=clr4;
				cancxt.beginPath();
				cancxt.arc(x1,y1,radius,0,Math.PI*2,true);
				cancxt.closePath();
				cancxt.fill();
				
				if(x1 == width||x1 == 0){
					dirX1 = dirX1*-1;
					}
				x1=x1+dirX1;
				if(y1 == height||y1 == 0){
					dirY1 = dirY1*-1;
					}
					
				radius = Math.random()*30;
				y1=y1+dirY1;
			}
		
		</script>
	</head>
	<body>
		<canvas id="canvas"></canvas>
	</body>
</html>
